/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package metodos;
import metodos.conectate;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author casl
 */
public class cliente extends javax.swing.JFrame {
DefaultTableModel modelo;
    /**
     * Creates new form cliente
     */
    public cliente() {
        initComponents();
        cargartablacliente("");
        inhabilitar();
        
    }

    void cargartablacliente(String valor)
    {
        String[] titulos = {"NIT", "RAZON SOCIAL", "TIPO SOCIEDAD", "OBJETO SOCIAL", "REP. LEGAL", "DIRECCION", "TELEFONO"};
        String[] registros = new String[7];
        String sSQL = "";
        modelo = new DefaultTableModel(null, titulos);
        conectate mysql = new conectate();
        Connection cn = mysql.Conectar();
        
        sSQL = "select * from cliente where concat(nit, ' ',rsocial, ' ',objsoc) like '%"+valor+"%';";
        try 
        {
            Statement st = cn.createStatement();
            ResultSet rs = st.executeQuery(sSQL);
            
            while (rs.next())
            {
              registros[0] = rs.getString("nit");
              registros[1] = rs.getString("rsocial");
              registros[2] = rs.getString("tipsoc");
              registros[3] = rs.getString("objsoc");
              registros[4] = rs.getString("repleg");
              registros[5] = rs.getString("direc");
              registros[6] = rs.getString("tel");
              modelo.addRow(registros);
            
            }
            tblConsulta.setModel(modelo);
            
        } catch (SQLException ex) 
        {
            JOptionPane.showMessageDialog(null, ex);
        }
        
    }
    String id_actualizar = "";
    void buscarclienteditar(String id)
    {
        String sSQL = "";
        String dni = "", pp = "", ts= "", os= "", rl= "", dr= "", tl= "";
        conectate mysql = new conectate();
        Connection cn = mysql.Conectar();
        
        sSQL = "select * from cliente where nit = "+id+";";
        try 
        {
            Statement st = cn.createStatement();
            ResultSet rs = st.executeQuery(sSQL);
            
            while (rs.next())
            {
              dni = rs.getString("nit");
              pp = rs.getString("rsocial");
              ts = rs.getString("tipsoc");
              os = rs.getString("objsoc");
              rl = rs.getString("repleg");
              dr = rs.getString("direc");
              tl = rs.getString("tel");
                     
            }
            txtnit.setText(dni);
            txtrasonsocial.setText(pp);
            txttiposociedad.setText(ts);
            txtobjetosocial.setText(os);
            txtrepresentantelegal.setText(rl);
            txtdireccion.setText(dr);
            txttelefono.setText(tl);
            id_actualizar = id;
        } catch (SQLException ex) 
        {
            JOptionPane.showMessageDialog(null, ex);
        }
        
    }
    
    void eliminarcliente(String id)
    {
        String sSQL = "";
        conectate mysql = new conectate();
        Connection cn = mysql.Conectar();
        sSQL = "delete from cliente where nit = "+id+";";
        
        try 
        {
            PreparedStatement pst = cn.prepareCall(sSQL);
            pst.execute();
        }
        catch (Exception ex) 
        {
            JOptionPane.showMessageDialog(null, ex);
        }
    }
    
    
    void agregarlimpiar()
    {
        txtnit.setText("");
        txtrasonsocial.setText("");
        txtobjetosocial.setText("");
        txtrepresentantelegal.setText("");
        txttiposociedad.setText("");
        txtdireccion.setText("");
        txttelefono.setText("");
        txtnit.requestFocus();
    }
    void habilitar()
    {
        txtnit.setEnabled(true);
        txtrasonsocial.setEnabled(true);
        txtobjetosocial.setEnabled(true);
        txtrepresentantelegal.setEnabled(true);
        txttiposociedad.setEnabled(true);
        txtdireccion.setEnabled(true);
        txttelefono.setEnabled(true);
        agregarlimpiar();
        btnguardar.setEnabled(true);
        btncancelar.setEnabled(true);
        
    }
    void inhabilitar()
    {
        txtnit.setEnabled(false);
        txtrasonsocial.setEnabled(false);
        txtobjetosocial.setEnabled(false);
        txtrepresentantelegal.setEnabled(false);
        txttiposociedad.setEnabled(false);
        txtdireccion.setEnabled(false);
        txttelefono.setEnabled(false);
        btnguardar.setEnabled(false);
        btncancelar.setEnabled(false);
        agregarlimpiar();
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        mneditar = new javax.swing.JMenuItem();
        mneliminar = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        btnagregaraceptar = new javax.swing.JButton();
        txtrepresentantelegal = new javax.swing.JTextField();
        txttiposociedad = new javax.swing.JTextField();
        txtdireccion = new javax.swing.JTextField();
        txtnit = new javax.swing.JTextField();
        txttelefono = new javax.swing.JTextField();
        txtrasonsocial = new javax.swing.JTextField();
        txtobjetosocial = new javax.swing.JTextField();
        btnagregarsalir = new javax.swing.JButton();
        btnguardar = new javax.swing.JButton();
        btncancelar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblConsulta = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();

        mneditar.setText("Modificar");
        mneditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mneditarActionPerformed(evt);
            }
        });
        jPopupMenu1.add(mneditar);

        mneliminar.setText("Eliminar");
        mneliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mneliminarActionPerformed(evt);
            }
        });
        jPopupMenu1.add(mneliminar);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("agregar datos");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Adionar Datos"));

        jLabel1.setText("NIT:");

        jLabel2.setText("RAZON SOCIAL:");

        jLabel3.setText("OBJETO SOCIAL:");

        jLabel4.setText("REPRESENTANTE LEGAL:");

        jLabel5.setText("TIPO SOCIEDAD:");

        jLabel6.setText("DIRECCION:");

        jLabel7.setText("TELEFONO:");

        btnagregaraceptar.setText("Nuevo");
        btnagregaraceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnagregaraceptarActionPerformed(evt);
            }
        });

        txtrepresentantelegal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtrepresentantelegalActionPerformed(evt);
            }
        });

        txttiposociedad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txttiposociedadActionPerformed(evt);
            }
        });

        txtdireccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtdireccionActionPerformed(evt);
            }
        });

        txtnit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnitActionPerformed(evt);
            }
        });

        txttelefono.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txttelefonoActionPerformed(evt);
            }
        });

        txtrasonsocial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtrasonsocialActionPerformed(evt);
            }
        });

        txtobjetosocial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtobjetosocialActionPerformed(evt);
            }
        });

        btnagregarsalir.setText("Salir");
        btnagregarsalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnagregarsalirActionPerformed(evt);
            }
        });

        btnguardar.setText("Guardar");
        btnguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnguardarActionPerformed(evt);
            }
        });

        btncancelar.setText("Cancelar");
        btncancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btncancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(180, 180, 180))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtrasonsocial)
                            .addComponent(txtnit, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtrepresentantelegal)
                            .addComponent(txtobjetosocial, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txttelefono)
                            .addComponent(txtdireccion, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txttiposociedad, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addContainerGap())))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(btnagregaraceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnguardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btncancelar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnagregarsalir))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtnit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtrasonsocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtobjetosocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtrepresentantelegal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txttiposociedad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txttelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnagregaraceptar)
                    .addComponent(btnagregarsalir)
                    .addComponent(btnguardar)
                    .addComponent(btncancelar))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar Datos"));

        tblConsulta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblConsulta.setComponentPopupMenu(jPopupMenu1);
        jScrollPane1.setViewportView(tblConsulta);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
        );

        jLabel8.setText("Buscar Cliente:");

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnBuscar)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnBuscar))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnagregarsalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnagregarsalirActionPerformed
     this.dispose();  
        
    }//GEN-LAST:event_btnagregarsalirActionPerformed

    private void txtrepresentantelegalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtrepresentantelegalActionPerformed
        txtrepresentantelegal.transferFocus();
    }//GEN-LAST:event_txtrepresentantelegalActionPerformed

    private void btnagregaraceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnagregaraceptarActionPerformed
        habilitar();
        agregarlimpiar();
        
    }//GEN-LAST:event_btnagregaraceptarActionPerformed

    private void btncancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btncancelarActionPerformed
        inhabilitar();
        
    }//GEN-LAST:event_btncancelarActionPerformed

    private void txtnitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnitActionPerformed
        txtnit.transferFocus();
    }//GEN-LAST:event_txtnitActionPerformed

    private void txtrasonsocialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtrasonsocialActionPerformed
        txtrasonsocial.transferFocus();
    }//GEN-LAST:event_txtrasonsocialActionPerformed

    private void txtobjetosocialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtobjetosocialActionPerformed
        txtobjetosocial.transferFocus();
    }//GEN-LAST:event_txtobjetosocialActionPerformed

    private void txttiposociedadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txttiposociedadActionPerformed
        txttiposociedad.transferFocus();
    }//GEN-LAST:event_txttiposociedadActionPerformed

    private void txtdireccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtdireccionActionPerformed
        txtdireccion.transferFocus();
    }//GEN-LAST:event_txtdireccionActionPerformed

    private void txttelefonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txttelefonoActionPerformed
        btnagregaraceptar.transferFocus();
    }//GEN-LAST:event_txttelefonoActionPerformed
    String accion = "Insertar";
    private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
     conectate mysql = new conectate();
     Connection cn = mysql.Conectar();
     
     String nit, rs, ts, os, rl, dr, tl;
     String sSQL = "";
     
     nit = txtnit.getText().toString();
     rs = txtrasonsocial.getText();
     ts = txttiposociedad.getText();
     os = txtobjetosocial.getText();
     rl = txtrepresentantelegal.getText();
     dr = txtdireccion.getText();
     tl = txttelefono.getText();
     
     if (accion.equals("Insertar"))
     {
         sSQL = "insert into cliente (nit, rsocial, tipsoc, objsoc, repleg, direc, tel)"+
            "values (?, ?, ?, ?, ?, ?, ?);";
         JOptionPane.showMessageDialog(null, "Los datos se insertaron");
         agregarlimpiar();
     }
     else if (accion.equals("Modificar"))
     {
        sSQL  = "update cliente set nit = ?, rsocial = ?, tipsoc = ?, objsoc = ?, repleg = ?, "+
                 "direc = ?, tel = ? where nit = "+id_actualizar+";";
        JOptionPane.showMessageDialog(null, "Los datos se han modificado");
        agregarlimpiar();
     }
        try {
            PreparedStatement pst = cn.prepareStatement(sSQL);
            pst.setString(1, nit);
            pst.setString(2, rs);
            pst.setString(3, ts);
            pst.setString(4, os);
            pst.setString(5, rl);
            pst.setString(6, dr);
            pst.setString(7, tl);
            
            int n = pst.executeUpdate();
            
            if (n > 0)
            {
                
                cargartablacliente("");
            }
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex);
        }
     
    }//GEN-LAST:event_btnguardarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        String valor = txtBuscar.getText();
        cargartablacliente(valor);
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void mneditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mneditarActionPerformed
        int filasel;
        String id;
        
        try 
        {
          filasel = tblConsulta.getSelectedRow();
          if (filasel == -1)
          {
              JOptionPane.showMessageDialog(null, "No se ha seleccionado ninguna fila");
          }
          else
          {
              accion = "Modificar";
              modelo = (DefaultTableModel) tblConsulta.getModel();
              id = (String) modelo.getValueAt(filasel, 0);
              habilitar();
              buscarclienteditar(id);
          }
        }
        catch (Exception e)
        {
        
        }
            
        
    }//GEN-LAST:event_mneditarActionPerformed

    private void mneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mneliminarActionPerformed
        int filasel;
        String id = null;
        
        try 
        {
            filasel = tblConsulta.getSelectedRow();
            if (filasel == -1)
                JOptionPane.showMessageDialog(null, "Selecione un registro a eliminar");
            else
                id = (String) modelo.getValueAt(filasel, 0);
                eliminarcliente(id);
                cargartablacliente("");
                
        } catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }//GEN-LAST:event_mneliminarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnagregaraceptar;
    private javax.swing.JButton btnagregarsalir;
    private javax.swing.JButton btncancelar;
    private javax.swing.JButton btnguardar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenuItem mneditar;
    private javax.swing.JMenuItem mneliminar;
    private javax.swing.JTable tblConsulta;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtdireccion;
    private javax.swing.JTextField txtnit;
    private javax.swing.JTextField txtobjetosocial;
    private javax.swing.JTextField txtrasonsocial;
    private javax.swing.JTextField txtrepresentantelegal;
    private javax.swing.JTextField txttelefono;
    private javax.swing.JTextField txttiposociedad;
    // End of variables declaration//GEN-END:variables
}
